//
// Created by kriko on 2021/7/9.
//


#include "str_cli09.h"
#include "sum.h"

void str_cli(FILE* fp, int sockfd) {
    char sendLine[MAXLINE] = {0};
    args_t args;
    result_t result;

    while(Fgets(sendLine, MAXLINE, fp) != NULL) {
        if (sscanf(sendLine, "%ld%ld", &args.arg1, &args.arg2) != 2) {
            printf("invalid input: %s\n", sendLine);
            continue;
        }
        Write(sockfd, &args, sizeof args);
        if (read(sockfd, &result, sizeof  result) == 0)
        {
            printf("str_cli: server terminated prematurely\n");
            return;
        }
        printf("%ld\n", result.sum);
    }
    return;
}